//
//  MLCountDownFreezeTime.m
//  WaterProof
//
//  Created by victor0321 on 12/1/8.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "MLCountDownFreezeTime.h"


@implementation MLCountDownFreezeTime

+(id)countDownWith:(CCProgressTimer *)timer Tag:(WeaponMask)tag{
    CCLOG(@"===========================================");
    CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self);
    return [[[self alloc] initWith:timer Tag:tag] autorelease];
}

-(id)initWith:(CCProgressTimer*)timer Tag:(WeaponMask)tag{
 
    if (self = [super init]) {
        time = timer;
        time.visible = YES;
        weaponMaskTag = tag;
        [self scheduleUpdate];
    }
    return self;
}

-(void)update:(ccTime)delta{
    switch (weaponMaskTag) {
        case MaskTubeVertical: case MaskTubeUpToRight: case MaskTubeHorizontal: case MaskTubeLeftToDown: case MaskTubeRightToDown: case MaskTubeUpToLeft:
            time.percentage -= delta*20;
            break;
        case MaskBucketSmall:
            time.percentage -= delta*15;
            break;
        case MaskBucketMiddle:
            time.percentage -= delta*10;
            break;
        case MaskBucketBig:
            time.percentage -= delta*5;
            break;
        default:
            break;
    }
    [[MLUserInterface sharedLayer] placeWeapon:weaponMaskTag approved:NO];
    if (time.percentage <= 0) {
        time.percentage = 100;
        [[MLUserInterface sharedLayer] placeWeapon:weaponMaskTag approved:YES]; 
        time.visible = NO;
        [self.parent removeChild:self cleanup:YES];
    }
}



-(void) dealloc
{
	CCLOG(@"===========================================");
    CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self);
	
	// don't forget to call "super dealloc"
	[super dealloc];
}

@end
